package ua.kharkov.knure.mikhaylov.st4.web.command;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;

import ua.kharkov.knure.mikhaylov.st4.db.entities.User;
import ua.kharkov.knure.mikhaylov.st4.db.management.DBManager;
import ua.kharkov.knure.mikhaylov.st4.settings.Path;

/**
 * Redirection command - browse user page
 * 
 * @author Saint
 * 
 */
public class BrowseUserPageCommand extends Command {

	private static final long serialVersionUID = -2187296739530334593L;
	private static final Logger log = Logger
			.getLogger(BrowseUserPageCommand.class);

	@Override
	public String execute(HttpServletRequest request,
			HttpServletResponse response) throws IOException, ServletException {

		log.debug("Redirecting to client page");

		int openPayments = DBManager.getInstance().countOpenPaymentsByUser(
				(User) request.getSession().getAttribute("user"));
		log.debug("Retrieved client's open payments --> " + openPayments);
		request.getSession().setAttribute("openPayments", openPayments);

		return Path.PAGE_CLIENT;
	}

}
